
<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml" lang="zh_CN">
  <head>
    <meta charset="utf-8" />
    <title>shelve --- Python 对象持久化 &#8212; Python 3.7.8 文档</title>
    <link rel="stylesheet" href="../_static/pydoctheme.css" type="text/css" />
    <link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
    
    <script type="text/javascript" id="documentation_options" data-url_root="../" src="../_static/documentation_options.js"></script>
    <script type="text/javascript" src="../_static/jquery.js"></script>
    <script type="text/javascript" src="../_static/underscore.js"></script>
    <script type="text/javascript" src="../_static/doctools.js"></script>
    <script type="text/javascript" src="../_static/language_data.js"></script>
    <script type="text/javascript" src="../_static/translations.js"></script>
    
    <script type="text/javascript" src="../_static/sidebar.js"></script>
    
    <link rel="search" type="application/opensearchdescription+xml"
          title="在 Python 3.7.8 文档 中搜索"
          href="../_static/opensearch.xml"/>
    <link rel="author" title="关于这些文档" href="../about.html" />
    <link rel="index" title="索引" href="../genindex.html" />
    <link rel="search" title="搜索" href="../search.html" />
    <link rel="copyright" title="版权所有" href="../copyright.html" />
    <link rel="next" title="marshal --- 内部 Python 对象序列化" href="marshal.html" />
    <link rel="prev" title="copyreg --- 注意 pickle 支持函数" href="copyreg.html" />
    <link rel="shortcut icon" type="image/png" href="../_static/py.png" />
    <link rel="canonical" href="https://docs.python.org/3/library/shelve.html" />
    
    <script type="text/javascript" src="../_static/copybutton.js"></script>
    
    
    
    
    <style>
      @media only screen {
        table.full-width-table {
            width: 100%;
        }
      }
    </style>
 

  </head><body>
  
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>导航</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../genindex.html" title="总目录"
             accesskey="I">索引</a></li>
        <li class="right" >
          <a href="../py-modindex.html" title="Python 模块索引"
             >模块</a> |</li>
        <li class="right" >
          <a href="marshal.html" title="marshal --- 内部 Python 对象序列化"
             accesskey="N">下一页</a> |</li>
        <li class="right" >
          <a href="copyreg.html" title="copyreg --- 注意 pickle 支持函数"
             accesskey="P">上一页</a> |</li>
        <li><img src="../_static/py.png" alt=""
                 style="vertical-align: middle; margin-top: -1px"/></li>
        <li><a href="https://www.python.org/">Python</a> &#187;</li>
        <li>
          <a href="../index.html">3.7.8 Documentation</a> &#187;
        </li>

          <li class="nav-item nav-item-1"><a href="index.html" >Python 标准库</a> &#187;</li>
          <li class="nav-item nav-item-2"><a href="persistence.html" accesskey="U">数据持久化</a> &#187;</li>
    <li class="right">
        

    <div class="inline-search" style="display: none" role="search">
        <form class="inline-search" action="../search.html" method="get">
          <input placeholder="快速搜索" type="text" name="q" />
          <input type="submit" value="转向" />
          <input type="hidden" name="check_keywords" value="yes" />
          <input type="hidden" name="area" value="default" />
        </form>
    </div>
    <script type="text/javascript">$('.inline-search').show(0);</script>
         |
    </li>

      </ul>
    </div>    

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body" role="main">
            
  <div class="section" id="module-shelve">
<span id="shelve-python-object-persistence"></span><h1><a class="reference internal" href="#module-shelve" title="shelve: Python object persistence."><code class="xref py py-mod docutils literal notranslate"><span class="pre">shelve</span></code></a> --- Python 对象持久化<a class="headerlink" href="#module-shelve" title="永久链接至标题">¶</a></h1>
<p><strong>源代码:</strong> <a class="reference external" href="https://github.com/python/cpython/tree/3.7/Lib/shelve.py">Lib/shelve.py</a></p>
<hr class="docutils" id="index-0" />
<p>&quot;shelf&quot; 是一种持久化的类似字典的对象。 与 &quot;dbm&quot; 数据库的区别在于 shelf 中的值（不是键！）实际上可以为任意 Python 对象 --- 即 <a class="reference internal" href="pickle.html#module-pickle" title="pickle: Convert Python objects to streams of bytes and back."><code class="xref py py-mod docutils literal notranslate"><span class="pre">pickle</span></code></a> 模块能够处理的任何东西。 这包括大部分类实例、递归数据类型，以及包含大量共享子对象的对象。 键则为普通的字符串。</p>
<dl class="function">
<dt id="shelve.open">
<code class="sig-prename descclassname">shelve.</code><code class="sig-name descname">open</code><span class="sig-paren">(</span><em class="sig-param">filename</em>, <em class="sig-param">flag='c'</em>, <em class="sig-param">protocol=None</em>, <em class="sig-param">writeback=False</em><span class="sig-paren">)</span><a class="headerlink" href="#shelve.open" title="永久链接至目标">¶</a></dt>
<dd><p>打开一个持久化字典。 filename 指定下层数据库的基准文件名。 作为附带效果，会为 filename 添加一个扩展名并且可能创建更多的文件。 默认情况下，下层数据库会以读写模式打开。 可选的 <em>flag</em> 形参具有与 <a class="reference internal" href="dbm.html#dbm.open" title="dbm.open"><code class="xref py py-func docutils literal notranslate"><span class="pre">dbm.open()</span></code></a> <em>flag</em> 形参相同的含义。</p>
<p>默认会使用第 3 版 pickle 协议来序列化值。  pickle 协议版本可通过 <em>protocol</em> 形参来指定。</p>
<p>由于 Python 语义的限制，shelf 无法确定一个可变的持久化字典条目在何时被修改。 默认情况下 <em>只有</em> 在被修改对象再赋值给 shelf 时才会写入该对象 (参见 <a class="reference internal" href="#shelve-example"><span class="std std-ref">示例</span></a>)。 如果可选的 <em>writeback</em> 形参设为 <code class="docutils literal notranslate"><span class="pre">True</span></code>，则所有被访问的条目都将在内存中被缓存，并会在 <a class="reference internal" href="#shelve.Shelf.sync" title="shelve.Shelf.sync"><code class="xref py py-meth docutils literal notranslate"><span class="pre">sync()</span></code></a> 和 <a class="reference internal" href="#shelve.Shelf.close" title="shelve.Shelf.close"><code class="xref py py-meth docutils literal notranslate"><span class="pre">close()</span></code></a> 时被写入；这可以使得对持久化字典中可变条目的修改更方便，但是如果访问的条目很多，这会消耗大量内存作为缓存，并会使得关闭操作变得非常缓慢，因为所有被访问的条目都需要写回到字典（无法确定被访问的条目中哪个是可变的，也无法确定哪个被实际修改了）。</p>
<div class="admonition note">
<p class="admonition-title">注解</p>
<p>请不要依赖于 shelf 的自动关闭功能；当你不再需要时应当总是显式地调用 <a class="reference internal" href="#shelve.Shelf.close" title="shelve.Shelf.close"><code class="xref py py-meth docutils literal notranslate"><span class="pre">close()</span></code></a>，或者使用 <a class="reference internal" href="#shelve.open" title="shelve.open"><code class="xref py py-func docutils literal notranslate"><span class="pre">shelve.open()</span></code></a> 作为上下文管理器:</p>
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="k">with</span> <span class="n">shelve</span><span class="o">.</span><span class="n">open</span><span class="p">(</span><span class="s1">&#39;spam&#39;</span><span class="p">)</span> <span class="k">as</span> <span class="n">db</span><span class="p">:</span>
    <span class="n">db</span><span class="p">[</span><span class="s1">&#39;eggs&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="s1">&#39;eggs&#39;</span>
</pre></div>
</div>
</div>
</dd></dl>

<div class="admonition warning">
<p class="admonition-title">警告</p>
<p>由于 <a class="reference internal" href="#module-shelve" title="shelve: Python object persistence."><code class="xref py py-mod docutils literal notranslate"><span class="pre">shelve</span></code></a> 模块需要 <a class="reference internal" href="pickle.html#module-pickle" title="pickle: Convert Python objects to streams of bytes and back."><code class="xref py py-mod docutils literal notranslate"><span class="pre">pickle</span></code></a> 的支持，因此从不可靠的来源载入 shelf 是不安全的。 与 pickle 一样，载入 shelf 时可以执行任意代码。</p>
</div>
<p>字典所支持的所有方法都被 shelf 对象所支持。 因此很容易将基于字典的代码转换为需要持久化存储的代码。</p>
<p>额外支持的两个方法：</p>
<dl class="method">
<dt id="shelve.Shelf.sync">
<code class="sig-prename descclassname">Shelf.</code><code class="sig-name descname">sync</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#shelve.Shelf.sync" title="永久链接至目标">¶</a></dt>
<dd><p>如果 shelf 打开时将 <em>writeback</em> 设为 <a class="reference internal" href="constants.html#True" title="True"><code class="xref py py-const docutils literal notranslate"><span class="pre">True</span></code></a> 则写回缓存中的所有条目。 如果可行还会清空缓存并将持久化字典同步到磁盘。 此方法会在使用 <a class="reference internal" href="#shelve.Shelf.close" title="shelve.Shelf.close"><code class="xref py py-meth docutils literal notranslate"><span class="pre">close()</span></code></a> 关闭 shelf 时自动被调用。</p>
</dd></dl>

<dl class="method">
<dt id="shelve.Shelf.close">
<code class="sig-prename descclassname">Shelf.</code><code class="sig-name descname">close</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#shelve.Shelf.close" title="永久链接至目标">¶</a></dt>
<dd><p>同步并关闭持久化 <em>dict</em> 对象。 对已关闭 shelf 的操作将失败并引发 <a class="reference internal" href="exceptions.html#ValueError" title="ValueError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">ValueError</span></code></a>。</p>
</dd></dl>

<div class="admonition seealso">
<p class="admonition-title">参见</p>
<p><a class="reference external" href="https://code.activestate.com/recipes/576642/">持久化字典方案</a>，使用了广泛支持的存储格式并具有原生字典的速度。</p>
</div>
<div class="section" id="restrictions">
<h2>限制<a class="headerlink" href="#restrictions" title="永久链接至标题">¶</a></h2>
<blockquote>
<div></div></blockquote>
<ul class="simple" id="index-1">
<li><p>可选择使用哪种数据库包 (例如 <a class="reference internal" href="dbm.html#module-dbm.ndbm" title="dbm.ndbm: The standard &quot;database&quot; interface, based on ndbm. (Unix)"><code class="xref py py-mod docutils literal notranslate"><span class="pre">dbm.ndbm</span></code></a> 或 <a class="reference internal" href="dbm.html#module-dbm.gnu" title="dbm.gnu: GNU's reinterpretation of dbm. (Unix)"><code class="xref py py-mod docutils literal notranslate"><span class="pre">dbm.gnu</span></code></a>) 取决于支持哪种接口。 因此使用 <a class="reference internal" href="dbm.html#module-dbm" title="dbm: Interfaces to various Unix &quot;database&quot; formats."><code class="xref py py-mod docutils literal notranslate"><span class="pre">dbm</span></code></a> 直接打开数据库是不安全的。 如果使用了 <a class="reference internal" href="dbm.html#module-dbm" title="dbm: Interfaces to various Unix &quot;database&quot; formats."><code class="xref py py-mod docutils literal notranslate"><span class="pre">dbm</span></code></a>，数据库同样会（不幸地）受限于它 --- 这意味着存储在数据库中的（封存形式的）对象尺寸应当较小，并且在少数情况下键冲突有可能导致数据库拒绝更新。</p></li>
<li><p><a class="reference internal" href="#module-shelve" title="shelve: Python object persistence."><code class="xref py py-mod docutils literal notranslate"><span class="pre">shelve</span></code></a> 模块不支持对 shelve 对象的 <em>并发</em> 读/写访问。 （多个同时读取访问则是安全的。） 当一个程序打开一个 shelve 对象来写入时，不应再有其他程序同时打开它来读取或写入。 Unix 文件锁定可被用来解决此问题，但这在不同 Unix 版本上会存在差异，并且需要有关所用数据库实现的细节知识。</p></li>
</ul>
<dl class="class">
<dt id="shelve.Shelf">
<em class="property">class </em><code class="sig-prename descclassname">shelve.</code><code class="sig-name descname">Shelf</code><span class="sig-paren">(</span><em class="sig-param">dict</em>, <em class="sig-param">protocol=None</em>, <em class="sig-param">writeback=False</em>, <em class="sig-param">keyencoding='utf-8'</em><span class="sig-paren">)</span><a class="headerlink" href="#shelve.Shelf" title="永久链接至目标">¶</a></dt>
<dd><p><a class="reference internal" href="collections.abc.html#collections.abc.MutableMapping" title="collections.abc.MutableMapping"><code class="xref py py-class docutils literal notranslate"><span class="pre">collections.abc.MutableMapping</span></code></a> 的一个子类，它会将封存的值保存在 <em>dict</em> 对象中。</p>
<p>默认会使用第 3 版 pickle 协议来序列化值。 pickle 协议版本可通过 <em>protocol</em> 形参来指定。 请参阅 <a class="reference internal" href="pickle.html#module-pickle" title="pickle: Convert Python objects to streams of bytes and back."><code class="xref py py-mod docutils literal notranslate"><span class="pre">pickle</span></code></a> 文档来查看 pickle 协议的相关讨论。</p>
<p>如果 <em>writeback</em> 形参为 <code class="docutils literal notranslate"><span class="pre">True</span></code>，对象将为所有访问过的条目保留缓存并在同步和关闭时将它们写回到 <em>dict</em>。 这允许对可变的条目执行自然操作，但是会消耗更多内存并让同步和关闭花费更长时间。</p>
<p><em>keyencoding</em> 形参是在下层字典被使用之前用于编码键的编码格式。</p>
<p><a class="reference internal" href="#shelve.Shelf" title="shelve.Shelf"><code class="xref py py-class docutils literal notranslate"><span class="pre">Shelf</span></code></a> 对象还可以被用作上下文管理器，在这种情况下它将在 <a class="reference internal" href="../reference/compound_stmts.html#with"><code class="xref std std-keyword docutils literal notranslate"><span class="pre">with</span></code></a> 语句块结束时自动被关闭。</p>
<div class="versionchanged">
<p><span class="versionmodified changed">在 3.2 版更改: </span>添加了 <em>keyencoding</em> 形参；之前，键总是使用 UTF-8 编码。</p>
</div>
<div class="versionchanged">
<p><span class="versionmodified changed">在 3.4 版更改: </span>添加了上下文管理器支持。</p>
</div>
</dd></dl>

<dl class="class">
<dt id="shelve.BsdDbShelf">
<em class="property">class </em><code class="sig-prename descclassname">shelve.</code><code class="sig-name descname">BsdDbShelf</code><span class="sig-paren">(</span><em class="sig-param">dict</em>, <em class="sig-param">protocol=None</em>, <em class="sig-param">writeback=False</em>, <em class="sig-param">keyencoding='utf-8'</em><span class="sig-paren">)</span><a class="headerlink" href="#shelve.BsdDbShelf" title="永久链接至目标">¶</a></dt>
<dd><p><a class="reference internal" href="#shelve.Shelf" title="shelve.Shelf"><code class="xref py py-class docutils literal notranslate"><span class="pre">Shelf</span></code></a> 的一个子类，将 <code class="xref py py-meth docutils literal notranslate"><span class="pre">first()</span></code>, <code class="xref py py-meth docutils literal notranslate"><span class="pre">next()</span></code>, <code class="xref py py-meth docutils literal notranslate"><span class="pre">previous()</span></code>, <code class="xref py py-meth docutils literal notranslate"><span class="pre">last()</span></code> 和 <code class="xref py py-meth docutils literal notranslate"><span class="pre">set_location()</span></code> 对外公开，在来自 <a class="reference external" href="https://www.jcea.es/programacion/pybsddb.htm">pybsddb</a> 的第三方 <code class="xref py py-mod docutils literal notranslate"><span class="pre">bsddb</span></code> 模块中可用，但在其他数据库模块中不可用。 传给构造器的 <em>dict</em> 对象必须支持这些方法。 这通常是通过调用 <code class="xref py py-func docutils literal notranslate"><span class="pre">bsddb.hashopen()</span></code>, <code class="xref py py-func docutils literal notranslate"><span class="pre">bsddb.btopen()</span></code> 或 <code class="xref py py-func docutils literal notranslate"><span class="pre">bsddb.rnopen()</span></code> 之一来完成的。  可选的 <em>protocol</em>, <em>writeback</em> 和 <em>keyencoding</em> 形参具有与 <a class="reference internal" href="#shelve.Shelf" title="shelve.Shelf"><code class="xref py py-class docutils literal notranslate"><span class="pre">Shelf</span></code></a> 类相同的含义。</p>
</dd></dl>

<dl class="class">
<dt id="shelve.DbfilenameShelf">
<em class="property">class </em><code class="sig-prename descclassname">shelve.</code><code class="sig-name descname">DbfilenameShelf</code><span class="sig-paren">(</span><em class="sig-param">filename</em>, <em class="sig-param">flag='c'</em>, <em class="sig-param">protocol=None</em>, <em class="sig-param">writeback=False</em><span class="sig-paren">)</span><a class="headerlink" href="#shelve.DbfilenameShelf" title="永久链接至目标">¶</a></dt>
<dd><p><a class="reference internal" href="#shelve.Shelf" title="shelve.Shelf"><code class="xref py py-class docutils literal notranslate"><span class="pre">Shelf</span></code></a> 的一个子类，它接受一个 <em>filename</em> 而非字典类对象。 下层文件将使用 <a class="reference internal" href="dbm.html#dbm.open" title="dbm.open"><code class="xref py py-func docutils literal notranslate"><span class="pre">dbm.open()</span></code></a> 来打开。 默认情况下，文件将以读写模式打开。 可选的 <em>flag</em> 形参具有与 <a class="reference internal" href="#shelve.open" title="shelve.open"><code class="xref py py-func docutils literal notranslate"><span class="pre">open()</span></code></a> 函数相同的含义。 可选的 <em>protocol</em> 和 <em>writeback</em> 形参具有与 <a class="reference internal" href="#shelve.Shelf" title="shelve.Shelf"><code class="xref py py-class docutils literal notranslate"><span class="pre">Shelf</span></code></a> 类相同的含义。</p>
</dd></dl>

</div>
<div class="section" id="example">
<span id="shelve-example"></span><h2>示例<a class="headerlink" href="#example" title="永久链接至标题">¶</a></h2>
<p>对接口的总结如下 (<code class="docutils literal notranslate"><span class="pre">key</span></code> 为字符串，<code class="docutils literal notranslate"><span class="pre">data</span></code> 为任意对象):</p>
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">shelve</span>

<span class="n">d</span> <span class="o">=</span> <span class="n">shelve</span><span class="o">.</span><span class="n">open</span><span class="p">(</span><span class="n">filename</span><span class="p">)</span>  <span class="c1"># open -- file may get suffix added by low-level</span>
                           <span class="c1"># library</span>

<span class="n">d</span><span class="p">[</span><span class="n">key</span><span class="p">]</span> <span class="o">=</span> <span class="n">data</span>              <span class="c1"># store data at key (overwrites old data if</span>
                           <span class="c1"># using an existing key)</span>
<span class="n">data</span> <span class="o">=</span> <span class="n">d</span><span class="p">[</span><span class="n">key</span><span class="p">]</span>              <span class="c1"># retrieve a COPY of data at key (raise KeyError</span>
                           <span class="c1"># if no such key)</span>
<span class="k">del</span> <span class="n">d</span><span class="p">[</span><span class="n">key</span><span class="p">]</span>                 <span class="c1"># delete data stored at key (raises KeyError</span>
                           <span class="c1"># if no such key)</span>

<span class="n">flag</span> <span class="o">=</span> <span class="n">key</span> <span class="ow">in</span> <span class="n">d</span>            <span class="c1"># true if the key exists</span>
<span class="n">klist</span> <span class="o">=</span> <span class="nb">list</span><span class="p">(</span><span class="n">d</span><span class="o">.</span><span class="n">keys</span><span class="p">())</span>     <span class="c1"># a list of all existing keys (slow!)</span>

<span class="c1"># as d was opened WITHOUT writeback=True, beware:</span>
<span class="n">d</span><span class="p">[</span><span class="s1">&#39;xx&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="p">[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">]</span>        <span class="c1"># this works as expected, but...</span>
<span class="n">d</span><span class="p">[</span><span class="s1">&#39;xx&#39;</span><span class="p">]</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="mi">3</span><span class="p">)</span>          <span class="c1"># *this doesn&#39;t!* -- d[&#39;xx&#39;] is STILL [0, 1, 2]!</span>

<span class="c1"># having opened d without writeback=True, you need to code carefully:</span>
<span class="n">temp</span> <span class="o">=</span> <span class="n">d</span><span class="p">[</span><span class="s1">&#39;xx&#39;</span><span class="p">]</span>             <span class="c1"># extracts the copy</span>
<span class="n">temp</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="mi">5</span><span class="p">)</span>             <span class="c1"># mutates the copy</span>
<span class="n">d</span><span class="p">[</span><span class="s1">&#39;xx&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">temp</span>             <span class="c1"># stores the copy right back, to persist it</span>

<span class="c1"># or, d=shelve.open(filename,writeback=True) would let you just code</span>
<span class="c1"># d[&#39;xx&#39;].append(5) and have it work as expected, BUT it would also</span>
<span class="c1"># consume more memory and make the d.close() operation slower.</span>

<span class="n">d</span><span class="o">.</span><span class="n">close</span><span class="p">()</span>                  <span class="c1"># close it</span>
</pre></div>
</div>
<div class="admonition seealso">
<p class="admonition-title">参见</p>
<dl class="simple">
<dt>模块 <a class="reference internal" href="dbm.html#module-dbm" title="dbm: Interfaces to various Unix &quot;database&quot; formats."><code class="xref py py-mod docutils literal notranslate"><span class="pre">dbm</span></code></a></dt><dd><p><code class="docutils literal notranslate"><span class="pre">dbm</span></code> 风格数据库的泛型接口。</p>
</dd>
<dt>模块 <a class="reference internal" href="pickle.html#module-pickle" title="pickle: Convert Python objects to streams of bytes and back."><code class="xref py py-mod docutils literal notranslate"><span class="pre">pickle</span></code></a></dt><dd><p><a class="reference internal" href="#module-shelve" title="shelve: Python object persistence."><code class="xref py py-mod docutils literal notranslate"><span class="pre">shelve</span></code></a> 所使用的对象序列化。</p>
</dd>
</dl>
</div>
</div>
</div>


          </div>
        </div>
      </div>
      <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
        <div class="sphinxsidebarwrapper">
  <h3><a href="../contents.html">目录</a></h3>
  <ul>
<li><a class="reference internal" href="#"><code class="xref py py-mod docutils literal notranslate"><span class="pre">shelve</span></code> --- Python 对象持久化</a><ul>
<li><a class="reference internal" href="#restrictions">限制</a></li>
<li><a class="reference internal" href="#example">示例</a></li>
</ul>
</li>
</ul>

  <h4>上一个主题</h4>
  <p class="topless"><a href="copyreg.html"
                        title="上一章"><code class="xref py py-mod docutils literal notranslate"><span class="pre">copyreg</span></code> --- 注意 <code class="xref py py-mod docutils literal notranslate"><span class="pre">pickle</span></code> 支持函数</a></p>
  <h4>下一个主题</h4>
  <p class="topless"><a href="marshal.html"
                        title="下一章"><code class="xref py py-mod docutils literal notranslate"><span class="pre">marshal</span></code> --- 内部 Python 对象序列化</a></p>
  <div role="note" aria-label="source link">
    <h3>本页</h3>
    <ul class="this-page-menu">
      <li><a href="../bugs.html">提交 Bug</a></li>
      <li>
        <a href="https://github.com/python/cpython/blob/3.7/Doc/library/shelve.rst"
            rel="nofollow">显示源代码
        </a>
      </li>
    </ul>
  </div>
        </div>
      </div>
      <div class="clearer"></div>
    </div>  
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>导航</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../genindex.html" title="总目录"
             >索引</a></li>
        <li class="right" >
          <a href="../py-modindex.html" title="Python 模块索引"
             >模块</a> |</li>
        <li class="right" >
          <a href="marshal.html" title="marshal --- 内部 Python 对象序列化"
             >下一页</a> |</li>
        <li class="right" >
          <a href="copyreg.html" title="copyreg --- 注意 pickle 支持函数"
             >上一页</a> |</li>
        <li><img src="../_static/py.png" alt=""
                 style="vertical-align: middle; margin-top: -1px"/></li>
        <li><a href="https://www.python.org/">Python</a> &#187;</li>
        <li>
          <a href="../index.html">3.7.8 Documentation</a> &#187;
        </li>

          <li class="nav-item nav-item-1"><a href="index.html" >Python 标准库</a> &#187;</li>
          <li class="nav-item nav-item-2"><a href="persistence.html" >数据持久化</a> &#187;</li>
    <li class="right">
        

    <div class="inline-search" style="display: none" role="search">
        <form class="inline-search" action="../search.html" method="get">
          <input placeholder="快速搜索" type="text" name="q" />
          <input type="submit" value="转向" />
          <input type="hidden" name="check_keywords" value="yes" />
          <input type="hidden" name="area" value="default" />
        </form>
    </div>
    <script type="text/javascript">$('.inline-search').show(0);</script>
         |
    </li>

      </ul>
    </div>  
    <div class="footer">
    &copy; <a href="../copyright.html">版权所有</a> 2001-2020, Python Software Foundation.
    <br />
    Python 软件基金会是一个非盈利组织。
    <a href="https://www.python.org/psf/donations/">请捐助。</a>
    <br />
    最后更新于 6月 29, 2020.
    <a href="../bugs.html">发现了问题</a>？
    <br />
    使用<a href="http://sphinx.pocoo.org/">Sphinx</a>2.3.1 创建。
    </div>

  </body>
</html>